<?php
namespace Api\Event;

class ActiveEvent extends BaseEvent
{
    public function lists($filter = '', $field = '', $p = 1, $limit = 10, &$total)
    {
        $map = ['status' => 1];
        $filter && $map = array_merge($map, $filter);

        $total = service('Active')->where($map)->count();
        if (!$total) {
            return [];
        }
        $query = service('Active')->where($map)->order('begin_date desc');
        if ($p && $limit) {
            $query->page($p)->limit($limit);
        }
        $field = $field ?: 'id,title,href,thumb,begin_date,end_date';
        $list = $query->field($field)->select();
        $res = [];
        foreach ($list as &$value) {
            uri_format($value['thumb']);
            $res[] = $value;
        }
        return $res;
    }
}